package common;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.apache.struts2.ServletActionContext;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class Common_Anychar {

	public static void output(Node node) {//将node的XML字符串输出到控制台request.getServletPath();
        TransformerFactory transFactory=TransformerFactory.newInstance();
        try {
            Transformer transformer = transFactory.newTransformer();
            transformer.setOutputProperty("encoding", "utf-8");
            transformer.setOutputProperty("indent", "yes");
            DOMSource source=new DOMSource();
            source.setNode(node);
            StreamResult result=new StreamResult();
            result.setOutputStream(System.out);
            
            transformer.transform(source, result);
        } catch (TransformerConfigurationException e) {
            e.printStackTrace();
        } catch (TransformerException e) {
            e.printStackTrace();
        }   
    }
    
    public static Node selectSingleNode(String express, Object source) {//查找节点，并返回第一个符合条件节点
        Node result=null;
        XPathFactory xpathFactory=XPathFactory.newInstance();
        XPath xpath=xpathFactory.newXPath();
        try {
            result=(Node) xpath.evaluate(express, source, XPathConstants.NODE);
        } catch (XPathExpressionException e) {
            e.printStackTrace();
        }
        
        return result;
    }
    
    public static NodeList selectNodes(String express, Object source) {//查找节点，返回符合条件的节点集。
        NodeList result=null;
        XPathFactory xpathFactory=XPathFactory.newInstance();
        XPath xpath=xpathFactory.newXPath();
        try {
            result=(NodeList) xpath.evaluate(express, source, XPathConstants.NODESET);
        } catch (XPathExpressionException e) {
            e.printStackTrace();
        }
        
        return result;
    }
    
    public static void saveXml(String fileName, Document doc) {//将Document输出到文件
        TransformerFactory transFactory=TransformerFactory.newInstance();
        try {
            Transformer transformer = transFactory.newTransformer();
            transformer.setOutputProperty("indent", "yes");
            DOMSource source=new DOMSource();
            source.setNode(doc);
            StreamResult result=new StreamResult();
            result.setOutputStream(new FileOutputStream(fileName));
            
            transformer.transform(source, result);
        } catch (TransformerConfigurationException e) {
            e.printStackTrace();
        } catch (TransformerException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }   
    }
    public void ff(){

		DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
        Element theBook=null, theElem=null, root=null;
        try {
            factory.setIgnoringElementContentWhitespace(true);
            
            DocumentBuilder db=factory.newDocumentBuilder();
            Document xmldoc=db.parse(new File("H:/sample_50.xml"));
            
            root=xmldoc.getDocumentElement();
            
            //--- 新建一本书开始 ----
            theBook=xmldoc.createElement("book");
            theElem=xmldoc.createElement("name");
            theElem.setTextContent("新书");
            theBook.appendChild(theElem);
            
            theElem=xmldoc.createElement("price");
            theElem.setTextContent("20");
            theBook.appendChild(theElem);
            theElem=xmldoc.createElement("memo");
            theElem.setTextContent("新书的更好看。");
            theBook.appendChild(theElem);
            root.appendChild(theBook);
            
            System.out.println("--- 新建一本书开始 ----");
            output(xmldoc);
            
            
            //--- 新建一本书完成 ----
            //--- 下面对《哈里波特》做一些修改。 ----
            //--- 查询找《哈里波特》----
            theBook=(Element) selectSingleNode("/books/book[name='哈里波特']", root);
            System.out.println("--- 查询找《哈里波特》 ----");
            output(theBook);
            //--- 此时修改这本书的价格 -----
            theBook.getElementsByTagName("price").item(0).setTextContent("15");//getElementsByTagName 返回的是NodeList，所以要跟上item(0)。另外，getElementsByTagName("price")相当于xpath 的".//price"。
            System.out.println("--- 此时修改这本书的价格 ----");
            output(theBook);
            //--- 另外还想加一个属性id，值为B01 ----
            theBook.setAttribute("id", "B01");
            System.out.println("--- 另外还想加一个属性id，值为B01 ----");
            output(theBook);
            //--- 对《哈里波特》修改完成。 ----
            //--- 要用id属性删除《三国演义》这本书 ----
            theBook=(Element) selectSingleNode("/books/book[@id='B02']", root);
            System.out.println("--- 要用id属性删除《三国演义》这本书 ----");
            output(theBook);
            theBook.getParentNode().removeChild(theBook);
            System.out.println("--- 删除后的ＸＭＬ ----");
            output(xmldoc);
            //--- 再将所有价格低于10的书删除 ----
            NodeList someBooks=selectNodes("/books/book[price<10]", root);
            System.out.println("--- 再将所有价格低于10的书删除 ---");
            System.out.println("--- 符合条件的书有　"+someBooks.getLength()+"本。 ---");
            for(int i=0;i<someBooks.getLength();i++) {
                someBooks.item(i).getParentNode().removeChild(someBooks.item(i));
            }
            output(xmldoc);
            saveXml("Test1_Edited.xml", xmldoc);
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
	/**
	 * @param args
	 * @throws Throwable 
	 */
	public static void main(String[] args) throws Throwable {
//		HttpServletRequest request= ServletActionContext.getRequest();
//		System.out.println(request.getServletPath()); //获取classes的根目录
//		String path = request.getSession().getServletContext().getRealPath("/");
//		HttpServletRequest requestkk = ServletActionContext.getRequest();
//		String savePath = requestkk.getContextPath();
//		System.out.println(savePath);
//		System.out.println(path);
//		String savePath = ServletActionContext.getRequest().getRealPath("");
//		Common_Anychar tt  = new Common_Anychar();
//		tt.WriXMLFlie();
	}
	
	
	/**
	 * 增加qst_OneLine.xml模版内容
	 * 本方法有7个参数
	 * 1.titSrc:标题名称   2.x_Str:x轴名称  3.y_Str:x轴名称
	 * 4.tool_str:标签名称   5.series_Str：series名称  6.data_List:结果数据集
	 * 7.path_Str:系统根目录  8.x_key x轴数据的key  9.y_key y轴数据的key
	 * 10.file_name : 要保存文件的相对路径及名称
	 * 
	 */
	public static void WriXMLFlie(String picTitleStr,String x_Str,String y_Str,String tool_str,String series_Str,List data_List,String path_Str,String x_key,String y_key,String file_name){
		DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
        Element theBook=null, theElem=null, root=null;
        try {
        	 factory.setIgnoringElementContentWhitespace(true);
             DocumentBuilder db=factory.newDocumentBuilder();
             Document xmldoc=db.parse(new File(path_Str+"/common/anychatXML/anyCharFolder/qst_OneLine.xml"));
             root=xmldoc.getDocumentElement();
            
             /**获取标题  并可以修改 begin**/
             Element theTitle=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/title", root);	//获取标题节点
             theBook=xmldoc.createElement("text");
             theBook.setTextContent(picTitleStr); 	//修改节点（标题）内容
             theTitle.appendChild(theBook);
//             output(theBook);
             /**获取标题  并可以修改 end**/
             /**x，y轴信息  begin**/
             Element theAxes=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/axes/x_axis/title", root);	//获取x轴标题节点 
             theElem=xmldoc.createElement("text"); //创建x-轴 
             theElem.setTextContent(x_Str); 	//x轴说明
             theAxes.appendChild(theElem);
             
             theAxes=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/axes/y_axis/title", root);	//获取x轴标题节点 
             theBook=xmldoc.createElement("text"); //创建x-轴 
             theBook.setTextContent(y_Str); 	//x轴说明
             theAxes.appendChild(theBook);
//             output(theBook);
             /**x，y轴信息  end**/  
             
             
             /**增加标签信息  begin**/
             Element theTool=(Element) selectSingleNode("/anychart/charts/chart/data_plot_settings/line_series/tooltip_settings", root);	//获取x轴标题节点 
             theElem=xmldoc.createElement("format"); //创建x-轴 
             theElem.setTextContent(tool_str); 	//x轴说明
             theTool.appendChild(theElem);
             /**增加标签信息  end**/
             
             /**增加数据节点 begin**/

             Element theBookh=(Element) selectSingleNode("/anychart/charts/chart/data", root);	//获取标题节点
             Element theSeries=xmldoc.createElement("series"); //创建x-轴 
             theSeries.setAttribute("name", series_Str);
//             System.out.println(data_List);
             for(int i=0;i<data_List.size();i++){
            	 Map getMap=(HashMap)data_List.get(i);
                 theBook=xmldoc.createElement("point");
                 theBook.setAttribute("name", getMap.get(x_key)+"");
                 theBook.setAttribute("y", getMap.get(y_key)+"");
                 theSeries.appendChild(theBook);
             }
             theBookh.appendChild(theSeries);
             /**增加数据节点 end**/
//           System.out.println("--- 返回的数据 ----");
//           output(xmldoc);

             saveXml(path_Str+file_name, xmldoc);
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
		
	}
	
	
	/**
	 * 增加dbt_OneLine.xml模版内容
	 * 本方法有7个参数
	 * 1.titSrc:标题名称   2.x_Str:x轴名称  3.y_Str:x轴名称
	 *  5.series_Str：series名称  6.data_List:结果数据集
	 * 7.path_Str:系统根目录  8.x_key x轴数据的key  9.y_key y轴数据的key
	 * 10.file_name : 要保存文件的相对路径及名称
	 * 
	 */
	public static void WriXMLFlie_dbt(String picTitleStr,String x_Str,String y_Str,String tool_str,String series_Str,List data_List,String path_Str,String x_key,String y_key,String file_name){
		DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
        Element theBook=null, theElem=null, root=null;
        try {
        	 factory.setIgnoringElementContentWhitespace(true);
             DocumentBuilder db=factory.newDocumentBuilder();
             Document xmldoc=db.parse(new File(path_Str+"/common/anychatXML/anyCharFolder/dbt_OneLine.xml"));
             root=xmldoc.getDocumentElement();
            
             /**获取标题  并可以修改 begin**/
             Element theTitle=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/title", root);	//获取标题节点
             theBook=xmldoc.createElement("text");
             theBook.setTextContent(picTitleStr); 	//修改节点（标题）内容
             theTitle.appendChild(theBook);
//             output(theBook);
             /**获取标题  并可以修改 end**/
             /**x，y轴信息  begin**/
             Element theAxes=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/axes/x_axis/title", root);	//获取x轴标题节点 
             theElem=xmldoc.createElement("text"); //创建x-轴 
             theElem.setTextContent(x_Str); 	//x轴说明
             theAxes.appendChild(theElem);
             
             theAxes=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/axes/y_axis/title", root);	//获取x轴标题节点 
             theBook=xmldoc.createElement("text"); //创建x-轴 
             theBook.setTextContent(y_Str); 	//x轴说明
             theAxes.appendChild(theBook);
//             output(theBook);
             /**x，y轴信息  end**/  
             
             
             /**增加标签信息  begin**/
             Element theTool=(Element) selectSingleNode("/anychart/charts/chart/data_plot_settings/bar_series/tooltip_settings", root);	//获取x轴标题节点 
             theElem=xmldoc.createElement("format"); //创建x-轴 
             theElem.setTextContent(tool_str); 	//x轴说明
             theTool.appendChild(theElem);
             /**增加标签信息  end**/
             
             /**增加数据节点 begin**/

             Element theBookh=(Element) selectSingleNode("/anychart/charts/chart/data", root);	//获取标题节点
             Element theSeries=xmldoc.createElement("series"); //创建x-轴 
             theSeries.setAttribute("name", series_Str);
//             System.out.println(data_List);
             for(int i=0;i<data_List.size();i++){
            	 Map getMap=(HashMap)data_List.get(i);
                 theBook=xmldoc.createElement("point");
                 theBook.setAttribute("name", getMap.get(x_key)+"");
                 theBook.setAttribute("y", getMap.get(y_key)+"");
                 theSeries.appendChild(theBook);
             }
             theBookh.appendChild(theSeries);
             /**增加数据节点 end**/
//           System.out.println("--- 返回的数据 ----");
//           output(xmldoc);

             saveXml(path_Str+file_name, xmldoc);
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
	
	/**
	 * 供用水-供水量-汇总分析-行政区供水量（公报）对比分析图  
	 * 属于复杂对比图
	 * @param picTitleStr	标题名称
	 * @param x_Str	x轴名称
	 * @param y_Str	y轴名称
	 * @param series_Str	series的名称内容 数组    [series1Name,series2Name,series3Name....]
	 * @param data_List 数据
	 * @param path_Str 工程路径
	 * @param x_key x轴的key
	 * @param y_key y轴的key 数组  [y_key1,y_key2,y_key3....]
	 * @param file_name 文件保存内容
	 * 
	 * series_Str数组与y_key数组的长度应该是一样  并且是一一对应的
	 */
	public static void WriXMLFlie_fz_dbt(String picTitleStr,String x_Str,String y_Str,List series_Str,List data_List,String path_Str,String x_key,List y_key,String totVal,String file_name){
		DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
        Element theBook=null, theElem=null, root=null;
        try {
        	 factory.setIgnoringElementContentWhitespace(true);
             DocumentBuilder db=factory.newDocumentBuilder();
             Document xmldoc=db.parse(new File(path_Str+"/common/anychatXML/anyCharFolder/dbt_ManyLine.xml"));
             root=xmldoc.getDocumentElement();
             /**获取标题  并可以修改 begin**/
             Element theTitle=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/title", root);	//获取标题节点
             theBook=xmldoc.createElement("text");
             theBook.setTextContent(picTitleStr); 	//修改节点（标题）内容
             theTitle.appendChild(theBook);
//             output(theBook);
             /**获取标题  并可以修改 end**/
             /**x，y轴信息  begin**/
             Element theAxes=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/axes/x_axis/title", root);	//获取x轴标题节点 
             theElem=xmldoc.createElement("text"); //创建x-轴 
             theElem.setTextContent(x_Str); 	//x轴说明
             theAxes.appendChild(theElem);
             
             theAxes=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/axes/y_axis/title", root);	//获取x轴标题节点 
             theBook=xmldoc.createElement("text"); //创建x-轴 
             theBook.setTextContent(y_Str); 	//x轴说明
             theAxes.appendChild(theBook);
             /**x，y轴信息  end**/  
             
             
             /**增加数据节点 begin**/

             Element theBookh=(Element) selectSingleNode("/anychart/charts/chart/data", root);	//获取标题节点
             
             
             for(int j=0;j<series_Str.size();j++){
            	  Element theSeries=xmldoc.createElement("series"); //创建x-轴 
                  theSeries.setAttribute("name", series_Str.get(j).toString());
                  String y_key_val=y_key.get(j).toString();
                  for(int i=0;i<data_List.size();i++){
                 	 Map getMap=(HashMap)data_List.get(i);
                      theBook=xmldoc.createElement("point");
                      theBook.setAttribute("name", getMap.get(x_key)+"");
                      theBook.setAttribute("y", getMap.get(y_key_val)+"");
                      theSeries.appendChild(theBook);
                  }
                  if((j+1)==series_Str.size()){
                	  Element extra_labels=xmldoc.createElement("extra_labels"); //创建x-轴 
                	  Element label1=xmldoc.createElement("label"); //创建x-轴
                	  Element format=xmldoc.createElement("format"); //创建x-轴
                	  Element font=xmldoc.createElement("font"); //创建x-轴
                	  font.setAttribute("size", "10");
                	  font.setAttribute("color", "Black");
                	  label1.setAttribute("enabled", "true");
                	  format.setTextContent("{%CategoryYSum}{numDecimals:2}");
                	  label1.appendChild(font);
                	  label1.appendChild(format);
                	  extra_labels.appendChild(label1);
                	  theSeries.appendChild(extra_labels);
                  }
                  theBookh.appendChild(theSeries);
             }

             saveXml(path_Str+file_name, xmldoc);
             /**增加数据节点 end**/
            
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	/**
	 * 
	 * @param picTitleStr 图的标题
	 * @param x_Str	x轴名称
	 * @param y_Str	y轴名称
	 * @param series_Str	series的名称内容 数组    [series1Name,series2Name,series3Name....]
	 * @param data_List	数据
	 * @param path_Str 基本路径
	 * @param x_key x的key
	 * @param y_key	y轴的key 数组  [y_key1,y_key2,y_key3....]
	 * @param file_name 文件保存内容
	 */
	public static void WriXMLFlie_qst_manyLine(String picTitleStr,String x_Str,String y_Str,List series_Str,
			List data_List,String path_Str,String x_key,List y_key,String file_name){
		DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
        Element theBook=null, theElem=null, root=null;
        try {
        	 factory.setIgnoringElementContentWhitespace(true);
             DocumentBuilder db=factory.newDocumentBuilder();
             Document xmldoc=db.parse(new File(path_Str+"/common/anychatXML/anyCharFolder/qst_Manyline.xml"));
             root=xmldoc.getDocumentElement();
             /**获取标题  并可以修改 begin**/
             Element theTitle=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/title", root);	//获取标题节点
             theBook=xmldoc.createElement("text");
             theBook.setTextContent(picTitleStr); 	//修改节点（标题）内容
             theTitle.appendChild(theBook);
//             output(theBook);
             /**获取标题  并可以修改 end**/
             /**x，y轴信息  begin**/
             Element theAxes=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/axes/x_axis/title", root);	//获取x轴标题节点 
             theElem=xmldoc.createElement("text"); //创建x-轴 
             theElem.setTextContent(x_Str); 	//x轴说明
             theAxes.appendChild(theElem);
             
             theAxes=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/axes/y_axis/title", root);	//获取x轴标题节点 
             theBook=xmldoc.createElement("text"); //创建x-轴 
             theBook.setTextContent(y_Str); 	//x轴说明
             theAxes.appendChild(theBook);
             /**x，y轴信息  end**/  
             
             
             /**增加数据节点 begin**/

             Element theBookh=(Element) selectSingleNode("/anychart/charts/chart/data", root);	//获取标题节点
             
             
             for(int j=0;j<series_Str.size();j++){
            	  Element theSeries=xmldoc.createElement("series"); //创建x-轴 
                  theSeries.setAttribute("name", series_Str.get(j).toString());
                  String y_key_val=y_key.get(j).toString();
                  for(int i=0;i<data_List.size();i++){
                 	 Map getMap=(HashMap)data_List.get(i);
                      theBook=xmldoc.createElement("point");
                      theBook.setAttribute("name", getMap.get(x_key)+"");
                      theBook.setAttribute("y", getMap.get(y_key_val)+"");
                      theSeries.appendChild(theBook);
                  }
//                  if((j+1)==series_Str.size()){
//                	  Element extra_labels=xmldoc.createElement("extra_labels"); //创建x-轴 
//                	  Element label1=xmldoc.createElement("label"); //创建x-轴
//                	  Element format=xmldoc.createElement("format"); //创建x-轴
//                	  Element font=xmldoc.createElement("font"); //创建x-轴
//                	  font.setAttribute("size", "10");
//                	  font.setAttribute("color", "Black");
//                	  label1.setAttribute("enabled", "true");
//                	  format.setTextContent("{%CategoryYSum}{numDecimals:4}");
//                	  label1.appendChild(font);
//                	  label1.appendChild(format);
//                	  extra_labels.appendChild(label1);
//                	  theSeries.appendChild(extra_labels);
//                  }
                  theBookh.appendChild(theSeries);
             }
             saveXml(path_Str+file_name, xmldoc);
             /**增加数据节点 end**/
            
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	/**
	 * 
	 * @param picTitleStr 图的标题
	 * @param x_Str	x轴名称
	 * @param y_Str	y轴名称
	 * @param series_Str	series的名称内容 数组    [series1Name,series2Name,series3Name....]
	 * @param data_List	数据
	 * @param path_Str 基本路径
	 * @param x_key x的key
	 * @param y_key	y轴的key 数组  [y_key1,y_key2,y_key3....]
	 * @param file_name 文件保存内容
	 */
	public static void WriXMLFlie_dbt_manyCum(String picTitleStr,String x_Str,String y_Str,List series_Str,
			List data_List,String path_Str,String x_key,List y_key,String file_name){
		DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
        Element theBook=null, theElem=null, root=null;
        try {
        	 factory.setIgnoringElementContentWhitespace(true);
             DocumentBuilder db=factory.newDocumentBuilder();
             Document xmldoc=db.parse(new File(path_Str+"/common/anychatXML/anyCharFolder/dbt_ManyCum.xml"));
             root=xmldoc.getDocumentElement();
             /**获取标题  并可以修改 begin**/
             Element theTitle=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/title", root);	//获取标题节点
             theBook=xmldoc.createElement("text");
             theBook.setTextContent(picTitleStr); 	//修改节点（标题）内容
             theTitle.appendChild(theBook);
//             output(theBook);
             /**获取标题  并可以修改 end**/
             /**x，y轴信息  begin**/
             Element theAxes=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/axes/x_axis/title", root);	//获取x轴标题节点 
             theElem=xmldoc.createElement("text"); //创建x-轴 
             theElem.setTextContent(x_Str); 	//x轴说明
             theAxes.appendChild(theElem);
             
             theAxes=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/axes/y_axis/title", root);	//获取x轴标题节点 
             theBook=xmldoc.createElement("text"); //创建x-轴 
             theBook.setTextContent(y_Str); 	//x轴说明
             theAxes.appendChild(theBook);
             /**x，y轴信息  end**/  
             
             
             /**增加数据节点 begin**/

             Element theBookh=(Element) selectSingleNode("/anychart/charts/chart/data", root);	//获取标题节点
             
             
             for(int j=0;j<series_Str.size();j++){
            	  Element theSeries=xmldoc.createElement("series"); //创建x-轴 
                  theSeries.setAttribute("name", series_Str.get(j).toString());
                  String y_key_val=y_key.get(j).toString();
                  for(int i=data_List.size();i>0;i--){
                	  
                 	 Map getMap=(HashMap)data_List.get(i-1);
                      theBook=xmldoc.createElement("point");
                      theBook.setAttribute("name", getMap.get(x_key)+"");
                      theBook.setAttribute("y", getMap.get(y_key_val)+"");
                      theSeries.appendChild(theBook);
                  }
                  theBookh.appendChild(theSeries);
             }
             saveXml(path_Str+file_name, xmldoc);
             /**增加数据节点 end**/
            
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
	/**
	 * maxval:最大值
	 * @param picTitleStr 图的标题
	 * @param x_Str	x轴名称
	 * @param y_Str	y轴名称
	 * @param series_Str	series的名称内容 数组    [series1Name,series2Name,series3Name....]
	 * @param data_List	数据
	 * @param path_Str 基本路径
	 * @param x_key x的key
	 * @param y_key	y轴的key 数组  [y_key1,y_key2,y_key3....]
	 * @param file_name 文件保存内容
	 * c_List 颜色
	 */
	public static void WriXMLFlie_hzfx_tbt(double maxval,String picTitleStr,String x_Str,String y_Str,List series_Str,
			List data_List,String path_Str,String x_key,List y_key,String file_name,List c_List,List q_List){
		DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
        Element theBook=null, theElem=null, root=null;
        try {
        	 factory.setIgnoringElementContentWhitespace(true);
             DocumentBuilder db=factory.newDocumentBuilder();
             Document xmldoc=db.parse(new File(path_Str+"/common/anychatXML/anyCharFolder/tbt_ManyCum.xml"));
             root=xmldoc.getDocumentElement();
             /**获取标题  并可以修改 begin**/
             Element theTitle=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/title", root);	//获取标题节点
             theBook=xmldoc.createElement("text");
             theBook.setTextContent(picTitleStr); 	//修改节点（标题）内容
             theTitle.appendChild(theBook);
//             output(theBook);
             /**获取标题  并可以修改 end**/
             /**x，y轴信息  begin**/
             Element theAxes=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/axes/x_axis/title", root);	//获取x轴标题节点 
             theElem=xmldoc.createElement("text"); //创建x-轴 
             theElem.setTextContent(x_Str); 	//x轴说明
             theAxes.appendChild(theElem);
             
             theAxes=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/axes/y_axis/title", root);	//获取x轴标题节点 
             theBook=xmldoc.createElement("text"); //创建x-轴 
             theBook.setTextContent(y_Str); 	//x轴说明
             theAxes.appendChild(theBook);
             /**x，y轴信息  end**/  
             
             /**设置最大值*/
             Element theMax=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/axes/y_axis/scale", root);	//获取x轴标题节点 
             theMax.setAttribute("maximum",(maxval*1.2)+"");
             theMax=(Element) selectSingleNode("/anychart/charts/chart/chart_settings/axes/extra_y_axis_1/scale", root);	//获取x轴标题节点 
             theMax.setAttribute("maximum",(maxval*1.2)+"");
             
             
             
             /**增加数据节点 begin**/

             Element theBookh=(Element) selectSingleNode("/anychart/charts/chart/data", root);	//获取标题节点
             

             System.out.println(q_List);
             for(int j=0;j<series_Str.size();j++){
            	  Element theSeries=xmldoc.createElement("series"); //创建x-轴 
                  theSeries.setAttribute("name", series_Str.get(j).toString());
                  theSeries.setAttribute("color",  c_List.get(j).toString());
                 if(!q_List.get(j).toString().isEmpty()){
                     theSeries.setAttribute("y_axis",  q_List.get(j).toString());
                 }
                  String y_key_val=y_key.get(j).toString();
                  for(int i=0;i<data_List.size();i++){
                	  
                 	 Map getMap=(HashMap)data_List.get(i);
                      theBook=xmldoc.createElement("point");
                      theBook.setAttribute("name", getMap.get(x_key)+"");
                      theBook.setAttribute("y", getMap.get(y_key_val)+"");
                      theSeries.appendChild(theBook);
                  }
                  theBookh.appendChild(theSeries);
             }
             saveXml(path_Str+file_name, xmldoc);
             /**增加数据节点 end**/
            
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
	
}
